home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacMETH 3.2.1 / MacMETH Manual 1992 / Manual Examples / FileExample.MOD < prev    next >
Encoding:
Text File  |  1992-10-09  |  808 b   |  34 lines  |  [TEXT/MEDT]

  1. MODULE FileExample;
  2.  
  3.     (* this program copies the file "Example.TXT" into the file "Copy.BAK".    *)
  4.     (* demonstrates the access to text files.    *)
  5.  
  6.     FROM FileSystem IMPORT File, Response, Lookup, Close, ReadChar, WriteChar;
  7.  
  8.       VAR     f,g: File;
  9.               ch: CHAR;
  10.   
  11. BEGIN
  12.       (* Open existing file f *)
  13.       Lookup(f,"Example.TXT",FALSE);
  14.       IF f.res = done THEN
  15.         (* Create new file g *)
  16.         Lookup(g,"Copy.BAK",TRUE);
  17.         IF g.res = done THEN
  18.               (* Copy f to g *)
  19.               LOOP
  20.                 ReadChar(f,ch);
  21.                 IF f.eof THEN EXIT END;
  22.                 WriteChar(g,ch);
  23.               END (* LOOP *);
  24.               Close(g);
  25.         ELSE
  26.               (* File g could not be created (disk full?). *)
  27.         END (* IF *);
  28.         Close(f);
  29.       ELSE
  30.         (* File f could not be opened (not existent?). *)
  31.       END (* IF *);
  32. END FileExample.
  33.  
  34.